package summary;

/**
 * @Author: 海琳琦
 * @Date: 2022/3/13 15:13
 * https://leetcode-cn.com/problems/convert-bst-to-greater-tree/
 */
public class Title538 {

    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        public TreeNode() {
        }

        public TreeNode(int val) {
            this.val = val;
        }

        public TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    int sum = 0;

    public TreeNode convertBST(TreeNode root) {
        if (root == null ) {
            return null;
        }
        root.right = convertBST(root.right);
        sum += root.val;
        root.val = sum;
        root.left = convertBST(root.left);
        return root;
    }







    int sum1;

    public TreeNode convertBST3(TreeNode root) {
        if (root == null) {
            return null;
        }
        convertBST3(root.right);
        sum1 += root.val;
        root.val = sum1;
        convertBST3(root.left);
        return root;
    }


    public static void main(String[] args) {

    }
}
